<?php
require_once 'BaseController.php';

/**
 * 【PC版】ご希望条件 コントローラ
 */
class Renew_HopeController extends Renew_BaseController
{

    /**
     * メインアクション
     */
    public function indexAction()
    {
        $params = $this->getParameters();

        $area = $params['Area'];
        $code = $params['Code'];

        $this->getPrefData($code);

        $params = $this->makeMainParams($params, $area, $code);
        $params['single'] = true;
        $params['target_0'] = $code;
        $params['search_type'] = $area;

        $this->makeTemplateParams($params);
        $this->displayBody2('index');
    }

    // ★★★地区複数選択か、駅複数選択→希望条件ページ転移
    public function postAction()
    {
        $params = $this->getParameters();

        $cat = $params['search_type'];
        $this->getPrefData($params['target_0']);
        $codes = $this->extractParams($params, 'target_');
        $params = $this->makeMainParams($params, $cat, $codes);

        // こだわり条件
        $this->_data['kodawari'] = $params['KodawariId'];

        $this->_data['kodawariprm'] = Apm_Config_Search::$KODAWARI_ID_PRM_LIST[$params['KodawariId']]['prm'];

        $params['targets'] = $codes;
        $this->makeTemplateParams($params);
        $this->displayBody2('index');
    }

    public function getPrefData($code)
    {
        $model = new Search_Model_Selareasearch();
        $c = substr($code, 0, 2);
        $this->_data['PrefInfo'] = $model->getSimpleArea($c);
        $this->_data['PrefName'] = $this->getPrefName($c);
        $this->_data['PrefNameJP'] = $this->getPrefNameJP($c);
        $this->_data['PrefNameJPWithoutPostfix'] = $this->getPrefNameWithoutPostfix($jp);
    }

    private function makeMainParams($params, $cat, $code)
    {
        // 地域検索
        if ($cat == 'area')
        {
            $params['SrhKbn'] = '01';

            $params = $this->addCodesToParams2($params, $code, 'PrefCd', 'CityCd');

            $model1 = new Search_Model_Selareasearch();
            $this->_data['Mapping_pref'] = $model1->getPrefNameByPrefCd($params);

            $model2 = new Search_Model_Selcyo();
            $this->_data['Mapping_city'] = $model2->getShikucyosonNameByShikucyosonCd($params);
        } // 路線検索
        else if ($cat == 'line')
        {
            $params['SrhKbn'] = '02';

            $params = $this->addCodesToParams2($params, $code, 'PrefCd', 'StCd');
            $params = $this->makeRailCodeParams($params, 'StCd');

            $model1 = new Search_Model_Selareasearch();
            $this->_data['Mapping_pref'] = $model1->getPrefNameByPrefCd($params);

            $model2 = new Search_Model_Selensen();
            $this->_data['Mapping_ensen'] = $model2->getRailNameByRailCd($params);

            $model3 = new Search_Model_Seleki();
            $this->_data['Mapping_eki'] = $model3->getStNameByStCd($params);
        }
        else
        {
        }
        return $params;
    }

    private function makeTemplateParams($params)
    {
        $meta_data = Apm_Bukkenurl::setCommonMeta($params['SrhKbn'], $params, $this->_data['research_data'], true);
        $this->_data['Mapping_page_title'] = $meta_data['new_page_title'];
        $this->_data['Mapping_params'] = $params;
        if ($meta_data['AREA_FULL'])
        {
            $this->_data['Mapping_city'][0]['M01_SHIKUCHOUSON'] = $meta_data['AREA_FULL'];
        }

        // こだわりページ条件
        $data = array();
        Apm_Seo::generateKodawariBlock($data, $params, array(), 1);
        $this->_data['CrossKodawari'] = $data['CrossKodawari'];
    }

    /**
     * SEO対策用のmetaタグに配置する文章を設定
     */
    protected function setSeoMeta()
    {
        $this->_meta_title = 'ご希望条件 【アパマンショップ】';
        $this->_meta_description = 'ご希望条件でお部屋を探すなら、不動産情報が満載のアパマンショップネットワーク。賃貸マンション・アパートなど、';
        $this->_meta_keywords = 'ご希望条件,';
    }

}
?>